<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class DriveCreate extends Page
{
       public $imgBack = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $btnAddType = null;
       public $btnDelType = null;
       public $edType = null;
       public $listType = null;
       public $JTDivType = null;
       public $btnShowType = null;
       public $JTGroupBox1 = null;
       public $compid = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $dpDate = null;
       public $cmbveh = null;
       public $Label6 = null;
       public $hiddenEmpId = null;
       public $memoComments = null;
       public $edRefNum = null;
       public $edCompLiability = null;
       public $edPtAssessed = null;
       public $edDesc = null;
       public $cmbType = null;
       public $Label4 = null;
       public $Label3 = null;
       public $Label2 = null;
       public $Label1 = null;
       public $chkpersonalinjury = null;
       public $chkatfault = null;
       public $lblMobile = null;
       public $lblJob = null;
       public $JTSiteTheme1 = null;
       public $lblBirthdate = null;
       public $Image1 = null;

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function btnDelTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var TypeIndex = document.getElementById('listType').selectedIndex;
       var TypeValue = document.getElementById('listType')[TypeIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxType3(TypeValue,comp);
       <?php

       }


       function btnAddTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addtype = document.getElementById('edType').value;
       var comp = document.getElementById('compid').value;
       AjaxType2(addtype,comp);
       document.DriveCreate.edType.value = "";
       <?php

       }

       function btnShowTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivType').Show();
       document.DriveCreate.edType.value = "";
       <?php

       }


       function btnCancelClick($sender, $params)
       {
       redirect('personnel_driving_list.php?emp='.$this->hiddenEmpId->getValue());


       }

       function clr_drive()
       {
       $this->dpDate->Text='';
       $this->edDesc->Text='';
       $this->edRefNum->Text='';
       $this->edPtAssessed->Text='';
       $this->edCompLiability->Text='';
       $this->memoComments->Text='&nbsp';


       $this->cmbveh->Clear();
       $this->cmbveh->AddItem('--Select--', null, null);
       $result_veh = mysql_query("select * from vehicle_tbl where company_id='1'");

       while($row_veh = mysql_fetch_array($result_veh))
       {
          $this->cmbveh->AddItem($row_veh['veh_num'], null, $row_veh['vehicle_id']);
       }

       $this->cmbType->Clear();
       $this->cmbType->AddItem('--Select--', null, null);
       $result_type = mysql_query("select value from lookup_personnel_tbl where company_id='".$_SESSION['company_id']."' AND category='driving history types'");

        while($row_type = mysql_fetch_array($result_type))
        {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
        }
       }

       function DriveCreateCreate($sender, $params)
       {
       $this->compid->Value = $_SESSION['company_id'];
       $emp = $_GET['emp'];
       $this->hiddenEmpId->setValue($emp);

       $this->imgBack->setLink('personnel_driving_list.php?emp='.$this->hiddenEmpId->getValue());

       $this->cmbveh->Clear();
       $this->cmbveh->AddItem('--Select--', null, null);
        $result_veh = mysql_query("select * from vehicle_tbl where company_id='1'");

        while($row_veh = mysql_fetch_array($result_veh))
        {
            $this->cmbveh->AddItem($row_veh['veh_num'], null, $row_veh['vehicle_id']);
        }


       $this->cmbType->Clear();
       $this->cmbType->AddItem('--Select--', null, null);
       $result_type = mysql_query("select value from lookup_personnel_tbl where company_id='".$_SESSION['company_id']."' AND category='driving history types'");

        while($row_type = mysql_fetch_array($result_type))
        {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
        }

        //list type
       $result_t = mysql_query("select value from lookup_personnel_tbl where company_id='".$_SESSION['company_id']."' AND category='driving history types'");

        while($row_t = mysql_fetch_array($result_t))
        {
            $this->listType->AddItem($row_t['value'], null, $row_t['value']);
        }

       $this->dpDate->Text='';
       $this->edDesc->Text='';
       $this->edRefNum->Text='';
       $this->edPtAssessed->Text='';
       $this->edCompLiability->Text='';
       $this->memoComments->Text='&nbsp';

       }

       function btnSubmitClick($sender, $params)
       {
       if($this->chkpersonalinjury->Checked==true)
       {
       $personal_injury = '1';
       }
       else
       {
       $personal_injury = '0';
       }

       if($this->chkatfault->Checked==true)
       {
       $at_fault = '1';
       }
       else
       {
       $at_fault = '0';
       }

       $vehicle_id = $this->cmbveh->getItemIndex();
       $emp_id = $this->hiddenEmpId->getValue();

       $result_emp = mysql_query("select * from employee_tbl where autoid='".$this->hiddenEmpId->getValue()."'");
       $row_emp = mysql_fetch_array($result_emp);


       $result_vehicle = mysql_query("SELECT * FROM vehicle_tbl WHERE vehicle_id='".$vehicle_id."'")
       or die("GET VEH_ID ".mysql_error());
       $row_veh = mysql_fetch_array($result_vehicle);

       // INSERT TO PERSONNEL DRIVING HISTORY
       $result = mysql_query("insert into emp_drivinghistory_tbl (emp_id,
       company_id,
       date,
       type,
       description,
       point_assessed,
       cost,
       ref_num,
       comments,
       at_fault,
       personal_injury,
       vehicle,
       veh_id)

       values ('".$this->hiddenEmpId->getValue()."',
       '".$_SESSION['company_id']."',
       '".$this->dpDate->Text."',
       '".$this->cmbType->getItemIndex()."',
       '".$this->edDesc->Text."',
       '".$this->edPtAssessed->Text."',
       '".$this->edCompLiability->Text."',
       '".$this->edRefNum->Text."',
       '".$this->memoComments->Text."',
       '".$at_fault."',
       '".$personal_injury."',
       '".$row_veh['veh_num'].' '.$row_veh['year'].''.$row_veh['manufacturer_name'].''.$row_veh['model_name']."',
       '".$this->cmbveh->getItemIndex()."')")or die("INSERT EMPLOYEE - ".mysql_error());

       //INSERT TO VEH INCIDENT REPORT
       $result = mysql_query("insert into veh_incident_tbl (vehicle_id,
       company_id,
       date,
       type,
       description,
       driver,
       cost,
       ref_num,
       comments)

       values ('".$vehicle_id."',
       '".$_SESSION['company_id']."',
       '".$this->dpDate->Text."',
       '".$this->cmbType->getItemIndex()."',
       '".$this->edDesc->Text."',
       '".$row_emp['lname'].','.$row_emp['fname']."',
       '".$this->edCompLiability->Text."',
       '".$this->edRefNum->Text."',
       '".$this->memoComments->Text."')");

       redirect('personnel_driving_list.php?emp='.$this->hiddenEmpId->getValue());


       }

}

global $application;

global $DriveCreate;

//Creates the form
$DriveCreate=new DriveCreate($application);

//Read from resource file
$DriveCreate->loadResource(__FILE__);

//Shows the form
$DriveCreate->show();

?>